package springcloud.service.impl;

import com.zixue.springcloud.entities.CommonResult;
import com.zixue.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import springcloud.dao.PaymentDao;
import springcloud.service.PaymentService;

import javax.annotation.Resource;

@Service
public class PaymentServiceImpl implements PaymentService {

    @Resource
    private PaymentDao paymentMapper;
    @Value("${server.port}")
    private String serverPort;

    @Override
    public CommonResult<Integer> create(Payment payment) {
        int i = paymentMapper.create(payment);
        if (i <= 0){
            return new CommonResult(404,"添加失败，端口号为："+ serverPort,0);
        }else {
            return new CommonResult(200,"添加成功，端口号为："+ serverPort,i);
        }

    }

    @Override
    public CommonResult<Payment> getPaymentById(Long id) {
        Payment payment = paymentMapper.getPaymentById(id);
        if (payment == null){
            return new CommonResult(400,"没有查到数据端口号为："+ serverPort,null);
        }else {
            return new CommonResult<>(200,"根据ID查到了数据，端口号为："+ serverPort,payment);
        }
    }
}
